#include "Actor.h"

Actor::Actor()
{
	m_pParent = NULL;
	m_bIsVisible = false;
	m_bMovesWithParent = true;
	m_bRotatesWithParent = true;

	m_qRotation = Quaternion::Identity;

	// TODO: Link self with actor manager.
}

Actor::~Actor()
{
	// TODO: Unlink self with actor manager.
}

void Actor::Initialize()
{
}

void Actor::LoadContent()
{
}

void Actor::Update(float elapsedTime)
{
	m_vPosition += m_vVelocity * elapsedTime;
}

void Actor::Draw()
{
}

void Actor::UnloadContent()
{
}

const Actor* Actor::GetParent() const
{
	return m_pParent;
}

const std::list<Actor*> Actor::GetChildren() const
{
	return m_pChildren;
}

const bool Actor::HasParent() const
{
	return m_pParent != NULL;
}

const Vector3f Actor::GetPosition() const
{
	return m_vPosition;
}

const Vector3f Actor::GetAbsolutePosition() const
{
	Vector3f absolutePosition = m_vPosition;

	// TODO: Actually getting proper value.

	return absolutePosition;
}

const Quaternion Actor::GetRotation() const
{
	return m_qRotation;
}

const Quaternion Actor::GetAbsoluteRotation() const
{
	// TODO: Verify correctness.
	Quaternion absoluteRotation = m_qRotation;

	if(HasParent())
	{
		absoluteRotation *= m_pParent->GetAbsoluteRotation();
	}

	return absoluteRotation;
}

const Vector3f Actor::GetVelocity() const
{
	return m_vVelocity;
}

const bool Actor::GetMovesWithParent() const
{
	return m_bMovesWithParent;
}

const bool Actor::GetRotatesWithParent() const
{
	return m_bRotatesWithParent;
}

void Actor::SetParent(Actor* parent)
{
	if(parent == NULL)
	{
		m_vPosition = GetAbsolutePosition();
	}

	if(HasParent())
	{
		if(m_bMovesWithParent)
		{
			// We're about to detatch from our current parent, so we need to
			// get our current absolute position so we don't 'snap' to our
			// new parent.
			m_vPosition = GetAbsolutePosition() - parent->GetPosition();
		}
	}
	else
	{
	}

	m_pParent = parent;
}

void Actor::SetPosition(const Vector3f& position)
{
	m_vPosition = position;
}
void Actor::SetRotation(const Quaternion& rotation)
{
	m_qRotation = rotation;
}

void Actor::SetVelocity(const Vector3f& velocity)
{
	m_vVelocity = velocity;
}

void Actor::SetVisible(bool visible)
{
	m_bIsVisible = visible;
}

void Actor::SetMovesWithParent(bool movesWithParent)
{
	m_bMovesWithParent = movesWithParent;
}

void Actor::SetRotatesWithParent(bool rotatesWithParent)
{
	m_bRotatesWithParent = rotatesWithParent;
}